package com.rp.demo;

import com.rp.pojo.User;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.json.JSONObject;
import org.springframework.boot.test.json.JsonbTester;

public class SheetHandler implements XSSFSheetXMLHandler.SheetContentsHandler {

    private User user = null;

    @Override
    public void startRow(int rowIndex) { //M每一行的开始,rowIndex代表的是每一个sheet的行索引
        if(rowIndex == 0){
            user = null;
        }else{
            user = new User();
        }

    }

    //处理每一行的所有单元格
    @Override
    public void cell(String cellName, String cellValue, XSSFComment xssfComment) {

        if(user != null){
            String letter = cellName.substring(0, 1);//每个单元格的首字母 A,B,C
            switch(letter){
                case "A":{
                    user.setId(Long.parseLong(cellValue));
                    break;
                }
                case "B":{
                    user.setUserName(cellValue);
                    break;
                }
                case "C":{
                    user.setPhone(cellValue);
                    break;
                }
                case "D":{
                   // user.setId(Long.parseLong(cellValue));
                }
                case "E":{
                    user.setAddress(cellValue);
                    break;
                }
            }


        }
    }



    //每一行的结束
    @Override
    public void endRow(int rowIndex) {

        if(rowIndex !=0){
            System.out.println(user);
        }
    }

}
